package com.geezdata.cps.sdk3rd.sms.provider;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.geezdata.cps.sdk3rd.sms.request.BalanceRequest;
import com.geezdata.cps.sdk3rd.sms.request.SmsRequest;
import com.geezdata.cps.sdk3rd.sms.response.SmsResult;

public class AXJProvider extends BaseProvider {	
	@Override
	protected boolean usePost() {
		return false;
	}
	
	@Override
	public String prepareSendUrl(SmsRequest request) {
		return request.getDownlink() + "?name=" + request.getUsername() + "&pass=" + request.getPassword();
	}
	
	@Override
	public Map<String, Object> prepareSendParams(SmsRequest request) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (request.getSubId() != null) {
			params.put("subid", request.getSubId());
		}
        params.put("mobiles", request.getMobiles());
        params.put("content", request.getContent());
        return params;
	}

	@Override
	public SmsResult parseSendResponse(String response) {
		if (StringUtils.isEmpty(response)) {
			return null;
		}
		
		SmsResult result = new SmsResult();
		String[] temp = response.split(",");
		if (temp.length > 0) {
			result.setBatchSn(temp[0]);
		}
		
		if (temp.length > 1) {
			result.setResponseCode(temp[1]);
		}
		
		return result;
	}
	
	@Override
	public String prepareQueryUrl(BalanceRequest request) {
		return request.getQueryurl() + "?name=" + request.getUsername() + "&pass=" + request.getPassword();
	}

	@Override
	public Integer parseQueryResponse(String response) {
		if (StringUtils.isEmpty(response)) {
			return null;
		}
		
		return Integer.parseInt(response);
	}

	@Override
	protected Map<String, Object> prepareQueryParams(BalanceRequest request) {
		return null;
	}
}
